import yaml,os
import configparser
import os

data_path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))),"data/data.yaml")
ini_path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "config/settings.ini")
file_path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "file/空背荧.jpg")

class FileRead:
    def __init__(self):
        self.data_path = data_path
        self.ini_path = ini_path
        self.file_path = file_path

    def read_data(self):
        # 1.打开yaml文件，限定编码方式，防止中文乱码
        f = open(self.data_path, encoding="utf-8")
        # 2.读取yaml文件
        data = yaml.safe_load(f)
        return data

    def read_ini(self):
        config = configparser.ConfigParser()#实例化configparser
        config.read(self.ini_path,encoding='utf-8')#通过configparser以utf-8编码的方式读取settings.ini
        return config

    def read_file(self):
        file = open(self.file_path,'rb')#'rb',编码方式是二进制
        return {'file': ('空背荧.jpg', file, 'image/jpg')}#content_type='image/jpg'

base_data = FileRead()
# 取settings.ini里的数据，方式如下
# print(base_data.read_ini()['host']['api_sit_url'])

